package com.pshare.framework.listener;


import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

public class CommonsMultipartResolverExt extends CommonsMultipartResolver {
	
	@Override
	public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
		//加载文件上传监听器
		Integer code = 0;
		String codestr = request.getParameter("code");
		if (StringUtils.isNotBlank(codestr)) {
			code = Integer.parseInt(codestr);
		}
		FileUpload fileUpload = super.getFileUpload();
		FileUploadListener progressListener = new FileUploadListener(code);
		fileUpload.setProgressListener(progressListener);
		return super.resolveMultipart(request);
	}
}
